package com.wang.cloud.common.auth.enums;

import cn.hutool.core.util.ObjectUtil;
import lombok.Getter;

import java.util.Objects;

/**
 * 定义系统用户-登录的设备类型
 *
 * @author wang ye
 * @date 2024/5/27
 */

@Getter
public enum LoginDeviceEnum {
    WEB("web", "网页端"),
    APP("APP", "app"),
    WX_MA("wxMa", "微信小程序"),
    WX_MP("wxMp", "微信公众号"),
    ;

    /**
     * 登录类型
     */
    private final String device;
    /**
     * 登录类型描述
     */
    private final String desc;

    LoginDeviceEnum(String device, String desc) {
        this.device = device;
        this.desc = desc;
    }

    /**
     * 未匹配-默认返回web端
     *
     * @param device
     * @return
     */
    public static LoginDeviceEnum getEnumByLoginDevice(String device) {
        if (ObjectUtil.isEmpty(device)) {
            return LoginDeviceEnum.WEB;
        }
        for (LoginDeviceEnum value : values()) {
            if (Objects.equals(value.getDevice(), device)) {
                return value;
            }
        }
        return LoginDeviceEnum.WEB;
    }
}